package servlet;

import bean.Result;
import dao.AddImageDao;
import utils.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/adduserimage.s")
public class AdduserImageServlet extends HttpServlet {

    AddImageDao dao=new AddImageDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final HttpSession session = req.getSession();
        final Integer userid = (Integer) session.getAttribute("userid");
        final String pic = req.getParameter("pic");
        Result result=null;
        final Map<String, Object> map = dao.queryimage( userid);
        try{

                dao.updateimage(pic,userid);
                result =new Result(1,"图片上传成功",null);

        }catch (Exception e){
                result=new Result(0,e.getMessage(),null);
        }

        Util.WriteJson(result,resp);
    }
}
